package eteam.aps.systemservice.service;

import cn.hutool.core.convert.Convert;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import eteam.aps.common.R;
import eteam.aps.common.exceptions.AuthException;
import eteam.aps.systeminterface.model.dto.ModuleoperDto;
import eteam.aps.systeminterface.model.dto.VerifyTokenDto;
import eteam.aps.systeminterface.model.entity.ModuleEntity;
import eteam.aps.systeminterface.service.ISystemController;
import eteam.aps.systemservice.bll.SystemBll;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 系统服务
 */
@Api(tags = "系统服务控制器")
@RestController
//@RequestMapping(value = "/api/system")
public class SystemController implements ISystemController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private SystemBll systemBll;

    /**
     * 获取用户菜单树形列表
     *
     * @return: 菜单树形列表
     */
    @ApiOperationSupport(order = 1, ignoreParameters = {})
    @ApiOperation(value = "获取菜单树形列表")
    @Override
    @RequestMapping(value = "/api/system/getmenulist", method = RequestMethod.GET)
    public R<List<ModuleEntity>> getModuleList() throws Exception, AuthException {
        VerifyTokenDto tokenDto = Convert.convert(VerifyTokenDto.class, request.getAttribute("tokenInfo"));
        return R.success(systemBll.getModuleListByTokenInfo(tokenDto));
    }

    /**
     * 获取所有模块树形列表
     *
     * @return: 所有模块树形列表
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取所有模块树形列表")
    @Override
    @RequestMapping(value = "/api/system/getmenutree", method = RequestMethod.GET)
    public R<List<ModuleEntity>> getModuleTree() throws Exception, AuthException {
        return R.success(systemBll.getModuleList());
    }

    /**
     * 【开放接口】获取已经设置【请求URL】的模块操作列表，此功能对应接口地址
     *
     * @return: 模块操作列表
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "获取已经设置【请求URL】的模块操作列表")
    @Override
    @RequestMapping(value = "/api/system/getmoduleopers", method = RequestMethod.GET)
    public R<List<ModuleoperDto>> getModuleopers() throws Exception, AuthException {
        return R.success(systemBll.getModuleopers());
    }
}
